9 const int MAXN
= 1000010;
13 void preocomputeBorder(const string
&needle
) {
14 int m
= needle
.size();
17 for (int i
= 0; i
< m
; ++i
) {
18 border
[i
+1] = border
[i
];
19 while (border
[i
+1] > -1 and needle
[border
[i
+1]] != needle
[i
]) {
20 border
[i
+1] = border
[border
[i
+1]];
24 for (int i
= 0; i
<= m
; ++i
) {
25 printf("%d ", border
[i
]);
32 while (scanf("%d", &m
) == 1) {
33 string needle
; getline(cin
, needle
);
35 preocomputeBorder(needle
);
39 for (int i
= 0; ; ++i
) {
41 if (c
== '\n' or c
== EOF
) break;
45 while (seen
> -1 and needle
[seen
] != c
) {
49 printf("%d\n", i
- m
+ 1);
50 seen
= border
[m
]; // There are no more characters in needle, so with the next input character let's try with the border of the whole needle.